"""
person1 = Person(name='骆昊', age=40)
person2 = person1
del person1
栈 ---> 临时变量/函数调用 ---> FILO ---> 小 / 快
    函数递归调用 ---> stackoverflow
堆 ---> 大 / 慢 ---> 对象
    Python对象创建 ---> 两阶段构造
        cls.__new__ ---> malloc ---> self
        obj.__init__ ---> 数据填到内存
    C语言：malloc ---> free ---> 内存泄露
    C++语言：new ---> delete

    Python自动化内存管理 ---> 引用计数 + 标记清理 + 分代收集
静态区 --->
    ~ 数据段
    ~ 只读数据段
    ~ 代码段
"""
# import sys
#
# sys.setrecursionlimit(100000)
import json
from functools import lru_cache
from urllib.parse import quote

import requests


@lru_cache()
def foo(num):
    if num in (1, 2):
        return 1
    return foo(num - 1) + foo(num - 2)


# for i in range(1, 121):
#     print(f'{i}: {foo(i)}')

# resp = requests.put('http://47.104.31.138:9200/douban/')
# print(resp.json())

# resp = requests.get('http://47.104.31.138:9200/douban/')
# print(resp.json())

# resp = requests.post(
#     url='http://47.104.31.138:9200/douban/movie/1/',
#     headers={
#         'content-type': 'application/json',
#     },
#     data=json.dumps({
#         "no": "1001",
#         "title": "肖申克的救赎",
#         "rank": 1,
#         "product": "美国",
#         "intro": "希望让人自由"
#     })
# )
# print(resp.json())

# resp = requests.get('http://47.104.31.138:9200/douban/movie/1/')
# print(resp.json())

resp = requests.get('http://47.104.31.138:9200/douban/movie/_search?q=人生&size=2')
print(resp.json())

resp = requests.post(
    url='http://47.104.31.138:9200/douban/movie/_search',
    headers={
        'content-type': 'application/json'
    },
    data=json.dumps({
        'query': {
            'bool': {
                'must': {'match': {'quote': '美国'}},
                'filter': {'range': {'star': {'gt': 8.5}}}
            }
        }
    }),
)
print(resp.json())
